package ren.kane.phoenix.design.prototype;

import java.util.Hashtable;

/**
 * @author renrk(1275) on 2018-10-07 8:56 PM
 **/
public class ShapeCache {

    private static Hashtable<String, Shape> shapeHashTable = new Hashtable<>();

    public static Shape getShape(String id) {
        Shape cachedShape = shapeHashTable.get(id);
        return (Shape) cachedShape.clone();
    }

    public static void loadCache() {
        Square square = new Square();
        square.setId("1");
        shapeHashTable.put(square.getId(), square);

        Rectangle rectangle = new Rectangle();
        rectangle.setId("2");
        shapeHashTable.put(rectangle.getId(), rectangle);
    }
}
